home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 39 / Issue 39.iso / pc / PCSoftware / RoboHelp / DISK1 / DATA.1 / bsscnbar.js < prev    next >
Encoding:
JavaScript  |  2000-05-26  |  10.1 KB  |  320 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // RoboHELPÆ Navigator Bar for WebHelp
  3. // Copyright © 1999-2000 eHelp Corporation.  All rights reserved.
  4.  
  5. // Version= 1.20
  6.  
  7. // Warning:  Do not modify this file.  It is generated by RoboHELPÆ and changes will be overwritten.
  8.  
  9. // This file is used to support Navigator bar in WebHelp
  10. // The main functions are Sync toc. Show or Hide Navigator Panel. 
  11.  
  12. // call onBsscNavHide() from bsscright frame.
  13. // Hide the bsscleft frame(Nav). and show the current topic.
  14.  
  15. // call onBsscNavShow() from any frame except bsscright.
  16. // Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
  17.  
  18. // call onBsscNavSync() from bsscright frame.
  19. // there will be two situation.
  20. // 1. Nav is visible.  Just Sync the toc.( show the Contents panel and highlight the related topic).
  21. // 2. Nav is invisible. First Show the Nav panel. and then Sync the toc.
  22.  
  23.  
  24. // onBsscNavSync(strRelHomePage) strRelHomePage is the Relative Path of the First Page, from the current page's view.
  25. // other function will be called by onContent(). do not call them directly.
  26.  
  27. // onBsscNavSync is modified from onContents() in SyncFromTopic.js. add support DHTML sync. 
  28.  
  29. // BsscNavHasNavFrame() determine the Nav frame exists or not
  30.  
  31.  
  32. var gbDHTML = false;
  33.  
  34. var strAgent   = navigator.userAgent.toLowerCase();
  35. var strVersion = navigator.appVersion.toLowerCase();
  36.  
  37. var gnVerMajor = parseInt(strVersion);
  38. var gnVerMinor = parseFloat(strVersion);
  39.  
  40. var gbNS     = ((strAgent.indexOf("mozilla") != -1) && ((strAgent.indexOf('spoofer') == -1) && (strAgent.indexOf('compatible') == -1)));
  41. var gbIE     = (strAgent.indexOf("msie") != -1);
  42. var gbOpera  = (strAgent.indexOf("opera") != -1);
  43. var gbHotJava= (strVersion.indexOf("hotjava") != -1);
  44.  
  45. var gbWin16   = ((strVersion.indexOf("win16") != -1) || (strVersion.indexOf("windows 3.1") != -1));
  46. var gbWindows = ((strAgent.indexOf("win") != -1) || (strAgent.indexOf("16bit") != -1));
  47. var gbMac     = (strAgent.indexOf("mac") != -1);
  48. var gbWebTV   = (strAgent.indexOf("webtv") != -1);
  49. var gbSunOS   = (strAgent.indexOf("sunos") != -1);
  50.  
  51. var gbNS2         = ((gbNS) && (gnVerMajor == 2));
  52. var gbNS3         = ((gbNS) && (gnVerMajor == 3));
  53. var gbNS4         = ((gbNS) && (gnVerMajor >= 4));
  54. var gbIE4         = ((gbIE) && (gnVerMajor >= 4));
  55. var gbIE3         = ((gbIE) && (gnVerMajor <= 3));
  56. var gbIE302before = ((gbIE3) && ((strAgent.indexOf("3.00") != -1)||(strAgent.indexOf("3.0a") != -1)||(strAgent.indexOf("3.0b")!=-1)||(strAgent.indexOf("3.01")!=-1))); 
  57.  
  58. var gbIE5      = ((gbIE4) && (strAgent.indexOf("msie 5") != -1));
  59.  
  60. var nViewFrameType = 2;  //1: DTHTML 2:Applet 3: HTML2 list
  61.  
  62. if (gbIE4 && gbDHTML) nViewFrameType = 1;
  63. if (gbIE4 && gbSunOS) nViewFrameType = 1;
  64.  
  65. if (gbWin16)          nViewFrameType = 3;
  66. if (gbIE3 && gbMac)   nViewFrameType = 3;
  67. if (gbNS2)            nViewFrameType = 3;
  68. if (gbNS3 && gbMac)   nViewFrameType = 3;
  69. if (gbOpera)          nViewFrameType = 3;
  70. if (gbHotJava)        nViewFrameType = 3;
  71. if (gbWebTV)          nViewFrameType = 3;
  72. if (gbIE302before)    nViewFrameType = 3;
  73.  
  74. if ((gbNS4) && (window.screen) && (window.screen.colorDepth == 4))
  75. {
  76.    nViewFrameType = 3;
  77. }
  78.  
  79. function BsscNavIsList() {
  80.     return (nViewFrameType == 3 || (gbIE4 && !gbIE5 && gbMac));
  81. }
  82.  
  83. var gbstrNavnAgent   = navigator.userAgent.toLowerCase();
  84.  
  85. var gbNavnNS    = false;
  86. var gbNavnIE    = false;
  87. gbNavnNS     = ((gbstrNavnAgent.indexOf("mozilla") != -1) && ((gbstrNavnAgent.indexOf('spoofer') == -1) && (gbstrNavnAgent.indexOf('compatible') == -1)));
  88. gbNavnIE        = (gbstrNavnAgent.indexOf("msie") != -1);
  89.  
  90. function BsscNavHasNavFrame()
  91. {
  92.     var bHomePage = false;
  93.     if(gbNavnIE)
  94.     {
  95.         // IE
  96.         if ((parent) && ("object" == typeof(parent.document)) && (parent.document.frames) && (parent.document.frames.length > 1))
  97.             if (parent.document.frames[0].name.indexOf("bsscleft") == 0) {
  98.                 bHomePage=true;
  99.             }
  100.  
  101.     } 
  102.     if(gbNavnNS)
  103.     {
  104.         // Netscape 
  105.         if((parent)&&(parent.frames)&&(parent.frames.length>1)) 
  106.             if (parent.frames[0].name.indexOf("bsscleft") == 0)
  107.                 bHomePage=true;
  108.     }
  109.     return bHomePage;
  110. }
  111.  
  112. // call onBsscNavHide() from bsscright frame.
  113. // Hide the bsscleft frame(Nav). and show the current topic.
  114. function onBsscNavHide()
  115. {
  116.     
  117.     if (BsscNavHasNavFrame()) {
  118.         var strURL = document.URL;
  119.         if (strURL.toLowerCase().indexOf("file://") == 0) {
  120.             strURL = _bsscnBarReplaceSpecialChar(strURL);
  121.         }
  122.         parent.window.location.replace(strURL);
  123.     }
  124. }
  125.  
  126. // call onBsscNavShow() from any frame except bsscright.
  127. // Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
  128. function onBsscNavShow(strRelHomePageShow)
  129. {
  130.     if (!BsscNavHasNavFrame()) {
  131.         var strRelHomePage = _bsscnBarReplaceSlash(strRelHomePageShow);
  132.     
  133.         var strCurrentURL = document.URL;
  134.         var strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  135.     
  136.         var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  137.         var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  138.     
  139.         var strAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  140.     
  141.         var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  142.         var strAbsHomePagePath = strAbsHomePagePath + "/";
  143.     
  144.         var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  145.         if (startpos != -1) {
  146.             strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  147.             if (strAbsHomePageURL.toLowerCase().indexOf("file://") == 0) 
  148.                 strAbsHomePageURL = _bsscnBarReplaceSpecialChar(strAbsHomePageURL);
  149.             location.replace(strAbsHomePageURL+"#" + strRelativeURL);
  150.         }
  151.     }
  152. }
  153.  
  154. function onBsscNavSync(strRelHomePageSync)
  155. {
  156.     var strRelHomePage = _bsscnBarReplaceSlash(strRelHomePageSync);
  157.     
  158.     var strCurrentURL = document.URL;
  159.     var strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  160.     
  161.     var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  162.     var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  163.     
  164.     var strAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  165.     
  166.     var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  167.     var strAbsHomePagePath = strAbsHomePagePath + "/";
  168.     
  169.     var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  170.     
  171.     if (startpos != -1) {
  172.         strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  173.         if (BsscNavHasNavFrame()) {
  174.             if(gbNavnIE) {// IE
  175.                 if (parent.document.frames[0].document.applets.length > 0) {
  176.                     if (typeof(parent.document.frames[0].document.applets["webhelp"]) != "undefined") {
  177.                         parent.document.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  178.                     }
  179.                 }
  180.                 else {
  181.                     // probably DHTML
  182.                     if (typeof(parent.document.frames[0].document.frames["Tabs"]) != "undefined") {
  183.                         var tabFrame = parent.document.frames[0].document.frames["Tabs"];
  184.                         _bsscnBarSelectTOC(strRelativeURL);
  185.                     } 
  186.                     else { // it must be list
  187.                     }
  188.                 }
  189.             }
  190.             else { // Probably Netscape.
  191.                 if (parent.frames[0].document.applets.length > 0) {
  192.                     if (typeof(parent.frames[0].document.applets["webhelp"]) != "undefined") {
  193.                         parent.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  194.                     }
  195.                 }
  196.                 else {
  197.                     // probably DHTML
  198.                     if (typeof(parent.document.frames[0].document.frames["Tabs"]) != "undefined") {
  199.                         _bsscnBarSelectTOC(strRelativeURL);
  200.                     }
  201.                     else { // it must be list
  202.                     }
  203.                 }
  204.             }
  205.         }
  206.         else
  207.             //location.replace(strAbsHomePageURL+"#" + strRelativeURL);
  208.             onBsscNavShow(strRelHomePage);
  209.     }
  210. }
  211.  
  212.  
  213. // replace %20 to ' '
  214. function _bsscnBarReplaceSpecialChar(strURL)
  215. {    
  216.     var strReplacedURL = "";
  217.     for (i = 0; i < strURL.length; i ++ )
  218.     {
  219.         if (strURL.charAt(i) == '%') {
  220.             if (strURL.substring(i + 1, i + 3) == "20") {
  221.                 strReplacedURL = strReplacedURL + " ";
  222.                 i += 2;
  223.             }
  224.         }
  225.         else
  226.             strReplacedURL = strReplacedURL + strURL.charAt(i);
  227.     }
  228.     return strReplacedURL;
  229. }
  230.  
  231.  
  232. // replace \\ to /
  233. function _bsscnBarReplaceSlash(strURL)
  234. {    
  235.     var strReplacedURL = "";
  236.     for (i = 0; i < strURL.length; i ++ )
  237.     {
  238.         if (strURL.charAt(i) == '\\') 
  239.             strReplacedURL = strReplacedURL + "/"
  240.         else
  241.             strReplacedURL = strReplacedURL + strURL.charAt(i);
  242.     }
  243.     return strReplacedURL;
  244. }
  245.  
  246. // generate absolute URL for the first page.
  247. function _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath)
  248. {
  249.     if (strCurrentPath.charAt(strCurrentPath.length - 1) == '/') 
  250.         strCurrentPath = strCurrentPath.substring(0, strCurrentPath.length -1);
  251.     for (;;) {
  252.         upDirPos = strRelHomePage.indexOf("../")
  253.         if (upDirPos == 0) {
  254.             DirPos = strCurrentPath.lastIndexOf("/")
  255.             if (DirPos != -1) {
  256.             strCurrentPath = strCurrentPath.substring(0, DirPos)
  257.             }
  258.             strRelHomePage = strRelHomePage.substring(3, strRelHomePage.length);
  259.         }
  260.         if (upDirPos != 0) break;
  261.     }
  262.     return strCurrentPath + "/" + strRelHomePage;
  263. }
  264.  
  265. function _bsscnBarGetPath(strURL)
  266. {
  267.     pathpos = strURL.lastIndexOf("/");
  268.     if (pathpos > 0)
  269.         return strURL.substring(0, pathpos);
  270.     else 
  271.         return "";
  272. }
  273.  
  274. function _bsscnBarGetFileName(strURL)
  275. {
  276.     pathpos = strURL.lastIndexOf("/");
  277.     if (pathpos > 0)
  278.         return strURL.substring(pathpos + 1, strURL.length);
  279.     else
  280.         return strURL;
  281. }
  282.  
  283. function _bsscnBarGetTabFrame()
  284. {
  285.     if(gbNavnIE) {// IE
  286.     //    return parent.document.frames[0].document.frames[1];
  287.         return parent.document.frames[0];
  288.     }
  289.     else { // Netscape
  290.         //return parent.frames[0].document.frames[1];
  291.         return parent.frames[0];
  292.     }
  293. }
  294.  
  295. function _bsscnBarSelectTOC(strRelativeURL)
  296. {
  297.     var TabFrame = _bsscnBarGetTabFrame();
  298.     var strURL = TabFrame.location.href;
  299.     var hashpos = strURL.indexOf("#");
  300.     if (hashpos != -1) {
  301.         strURL = strURL.substring(0, hashpos);
  302.     }
  303.     //TabFrame.document.location = strURL + "#" + strRelativeURL;
  304.     //TabFrame.document.location.reload();
  305.     if ("function" == typeof(TabFrame.syncToc))
  306.         TabFrame.syncToc(strRelativeURL);
  307.     //alert(strRelativeURL);
  308. }
  309.  
  310.  
  311. function _bsscnBarOnError(message)
  312. {
  313.     if(-1 != message.indexOf("denied") 
  314.         || -1 != message.indexOf("Object required"))
  315.      return true;
  316. }
  317.  
  318. onerror = _bsscnBarOnError;
  319.  
  320.